package webcert.ch01.ex0102;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

public class WeatherParams extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.write("<html>\n<head>\n<title>" + "Display Weather Parameters</title>\n</head>\n<body>");

        Enumeration<String> params = request.getParameterNames();

        while (params.hasMoreElements()) {

            String param = params.nextElement();

            out.write("<h4>Parameter: " + param + "</h4>");

            for(String value : request.getParameterValues(param)) {
                out.write(value +  "<br />");
            }
        }

        out.write("\n</body>\n</html>");
        out.close();
    }
}
